#include<stdio.h>
char str[20];

int my_printf(int num, int radix)
{
    int i = 0, j = 0;
    char tmp[20];
    while(num != 0){
        tmp[j++] = '0' + num % radix;  
        num /= radix;
    }
    j--;
    for(;j >= 0; j--)
        str[i++] = tmp[j];
    return 0;
}
char *itof(int num, char *str, int radix) 
{
    char string[] = "0123456789abcdefghijklmnopqrstuvwxyz";

    char* ptr = str;
    int i = 0;
    int j = 0;
    int k = 0;
    
    if(num == 0)
    {
        str[0]='0';
        str[1]=0;
        return str;
    }

    while (num)
    {
        k = num -(num/radix)*radix;
        *ptr++ = string[k];
        num /= radix;

        if (num < radix)
        {
            *ptr++ = string[num];
            *ptr = '\0';
            break;
        }
    }

    j = ptr - str - 1;

    //exchange number sequence
    for (i = 0; i < (ptr - str) / 2; i++)
    {
        int temp = str[i];
        str[i] = str[j];
        str[j--] = temp;
    }

    return str;
}
char str1[20];
int main(int argc, char *argv[])
{
    my_printf(14, 10);
    itof(14, str1, 10);
    printf("str1 = %s\n", str1);
    printf("str = %s\n", str);
    return 0;
}
